package com.zs.ktsms.service.impl;

import com.zs.ktsms.mapper.SysUserMapper;
import com.zs.ktsms.pojo.SysUser;
import com.zs.ktsms.service.SysUserService;
import com.zs.ktsms.utils.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/31 下午9:10
 */
@Service
public class SysUserServiceImpl implements SysUserService {

    @Resource
    private SysUserMapper sysUserMapper;
    /**
     * 获取分页对象
     *
     * @param realName
     * @param roleId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public Page<SysUser> getPage(String realName, Long roleId, Integer pageNo, Integer pageSize) {
        Page<SysUser> page = new Page<>();
        page.setPageSize(pageSize);
        page.setTotalCount(sysUserMapper.count(realName,roleId));
        page.setPageNo(pageNo);
        int offset = (page.getPageNo()-1)*page.getPageSize();
        page.setData(sysUserMapper.selectAll(realName,roleId,offset,page.getPageSize()));
        return page;
    }

    /**
     * 登录
     *
     * @param realName
     * @param password
     * @return
     */
    @Override
    public SysUser select(String realName, String password) {
        return sysUserMapper.select(realName,password);
    }

    /**
     * 添加
     *
     * @param sysUser
     * @return
     */
    @Override
    public int add(SysUser sysUser) {
        return sysUserMapper.add(sysUser);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int delete(Integer id) {
        return sysUserMapper.delete(id);
    }

    /**
     * 修改用户
     *
     * @param sysUser
     * @return
     */
    @Override
    public int update(SysUser sysUser) {
        return sysUserMapper.update(sysUser);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public int detail(Integer id) {
        return sysUserMapper.detail(id);
    }

    /**
     * 修改密码
     *
     * @param id
     * @param password
     * @return
     */
    @Override
    public int modifyPassword(Integer id, Integer password) {
        return sysUserMapper.modifyPassword(id,password);
    }
}
